<<<<<<< .mine
var solutionMain1 = [[Repeat,3],[Forward,150],[Left,120],[Fx,0]];
var solutionMain2 = [[Repeat,3],[Fx,0],[Forward,150],[Left,120]];
var solutionFun = [[Repeat,3],[Forward,50],[Right,120]];

/**
 * @class
 * @augments Sprite 
 * @augments Level  
 * @description level Korytnacka
 *     
 */ 
function TurtleLevel(type){
    this.name = "levelTurtle";
    this.picturePath = Game.picturesPath + "levels/"+this.name + "/";
    Sprite.apply(this);
    Level.apply(this);
    // nastavenie panelu
    this.requiredTime = 70;
    this.type = type;
    this.panel = new ProgramPanel();
    this.panel.x = MainContainerWidth - this.panel.width - MARGIN;
    this.panel.y = MARGIN;
    this.addChild(this.panel);
                
    // nastavenie buttonu pre kreslenie           
    this.drawButton = new Button("Draw");
    this.drawButton.x = this.panel.x;//this.main.width + MARGIN;
    this.drawButton.y = this.panel.main.height + 2*MARGIN;
    this.addChild(this.drawButton);
    
    // nastavenie textu            
    this.text = new TextField();
    this.text.setTextFormat(new TextFormat(font, commandSize+5, white));
    this.text.text = "Can you make this ?!"; 
    this.text.width = this.text.textWidth; 
    this.text.height = this.text.textHeight;
    this.text.x = this.panel.x + 40;
    this.text.y = this.panel.main.height + 7*MARGIN;
    this.addChild(this.text);
    
    // start pre korytnacku            
    this.startX = this.panel.x - 200;
    this.startY = MainContainerHeight - 200;
    
    //
    this.exampleTurtle =  new Turtle(MainContainerWidth/2 + 300, MainContainerHeight/2 + 140);
    
    this.drawExample = function(){
        for(var i = 0;i < 3;i++){
            this.triangle();
            this.exampleTurtle.fd(150);
            this.exampleTurtle.lt(120);
        }
    }
    
    this.triangle = function(){
        for(var i = 0;i < 3;i++){
            this.exampleTurtle.fd(50);
            this.exampleTurtle.rt(120);
        }
    }
    
    this.drawExample();
    this.addChild(this.exampleTurtle);
    this.exampleTurtle.draw();
                
    // vytvorenie kroytnacky            
    this.turtle = new Turtle(this.startX, this.startY);
    this.addChild(this.turtle);
    
    /**
    * @function
    * @description vycistenie plochy
    */    
    this.clear = function(){
        this.turtle.clear();
    }
             
    /**
    * @function
    * @description funkcia rekurzivne simulujuca program zadany do command panelov
    * @param index {number}     
    * @param commands {Array of commands} object.command, object.value , prikazy Main funkcie
    * @param helpCommands {Array of commands}  prikazy pomocnej funkcie        
    */             
    this.fun = function(index,commands, helpCommands){
        // ak nie su prikazi ukonci sa
        if(index >= commands.length){
            return;
        }
                    
        var command = commands[index].command;
        var value = commands[index].value;
        // podla commandu sa rozhodne ako dalej
        switch(command){
            case Forward:
                this.turtle.fd(value);                      // dopredu
                this.fun(index + 1,commands,helpCommands);  // vnorenie
                break;   
            case Right:
                this.turtle.rt(value);                      // zatocenie vpravo
                this.fun(index + 1,commands,helpCommands);  // vnorenie
                break;
            case Left:
                this.turtle.lt(value);                      // zatocenie vlavo
                this.fun(index + 1,commands,helpCommands);  // vnorenie
                break;
            case Fx:
                if(helpCommands != null){
                    this.fun(0,helpCommands,null);    // vykonanie prikazov pomocnej funkcie (funkcia nemoze volat samu seba)
                }
                this.fun(index + 1,commands,helpCommands);  // vnorenie
                break;   
            case Repeat:
                if(value > 20){   // zla hodnota (nemoze nastat)
                    break;
                }
                for(var i = 0;i < value;i++){  // simulacia forcyklu
                    this.fun(index + 1,commands,helpCommands);   // vnorenie
                }
                break;
            default:
                console.debug("wrong command");
        }
    }
                
    /**
    * @function
    * @description z prikazov vytvori obrazok kroytnacky
    */              
    this.generatePicture = function(){
        var main = this.panel.getMainCommands();
        var helpCommands = this.panel.getFunCommands();
        this.fun(0,main,helpCommands);
                    
    }
    
    /**
    * @function
    * @description porovna 2 polia commandov
    * @param cmds {Array of commands} testovane prikazy
    * @param sol {Array of commands}  riesenie   
    */   
    function compare(cmds, sol){
        if(cmds.length != sol.length){
            return false;
        }
        for(var i = 0;i < cmds.length;i++){
            var cmd = cmds[i].command;
            var val = cmds[i].value;
            if(cmd == Fx){
                if(sol[i][0] != Fx){
                    return false;
                }
            }else{
                if(cmd != sol[i][0] || val != sol[i][1]){
                    return false;
                }
            }
        }
        return true;
    }
    
    /**
    * @function
    * @description level moze mat 2 rozne riesenia, ktore treba otestovat
    * @return {true} level bol uspesne vyrieseny  
    * @return {true} level este nebol vyrieseny spravne      
    */   
    this.isSolved = function(){
        var result = false;
        var main = this.panel.getMainCommands();
        var funct = this.panel.getFunCommands();
        result |= compare(main,solutionMain1);
        result |= compare(main,solutionMain2);
        result &= compare(funct,solutionFun);
        if (result)
            this.timer.TimerStop();
        return result;
    }
    
    /**
    * @function
    * @description kliknutim na tlacidlo Draw vycisti plochu a vykresli obrazok podla prikazov  
    */             
    this.drawClick = function(e){
        var toto = e.target.parent;
        toto.clear();
        //toto.turtle.angle = 0;
        //toto.turtle.points = [];
        toto.turtle.setXY(toto.startX, toto.startY);
        toto.generatePicture();  
        toto.turtle.draw();
        if(toto.isSolved()){
            toto.levelSolved();
        //alert('gratulujem'); 
        }
    }
    this.drawButton.addEventListener(MouseEvent.CLICK,this.drawClick);
                
    // Draw start            
    
    this.graphics.beginFill(red);
    this.graphics.drawCircle(this.startX, this.startY,4);
    this.graphics.endFill();
    
    this.startText = new TextField();
    this.startText.setTextFormat(new TextFormat(font, commandSize+5, red));
    this.startText.text = "START"; 
    this.startText.width = this.startText.textWidth + 10; 
    this.startText.height = this.startText.textHeight;
    this.startText.x = this.startX + 2;
    this.startText.y = this.startY + 2;
    this.addChild(this.startText);
                
    this.manual = new Manual (this.picturePath);
    this.addChild (this.manual); 
}
            
TurtleLevel.prototype = new Sprite();=======
var solutionMain1 = [[Repeat,3],[Forward,150],[Left,120],[Fx,0]];
var solutionMain2 = [[Repeat,3],[Fx,0],[Forward,150],[Left,120]];
var solutionFun = [[Repeat,3],[Forward,50],[Right,120]];


function TurtleLevel(){
    Sprite.apply(this);
    Level.apply(this);
    this.panel = new ProgramPanel();
    this.panel.x = cwidth - this.panel.width - MARGIN;
    this.panel.y = MARGIN;
    this.addChild(this.panel);
                
               
    this.drawButton = new Button("Draw");
    this.drawButton.x = this.panel.x;//this.main.width + MARGIN;
    this.drawButton.y = this.panel.main.height + 2*MARGIN;
    this.addChild(this.drawButton);
                
    this.text = new TextField();
    this.text.setTextFormat(new TextFormat(font, commandSize+5, red));
    this.text.text = "Can you make this ?!"; 
    this.text.width = this.text.textWidth; 
    this.text.height = this.text.textHeight;
    this.text.x = this.panel.x + 40;
    this.text.y = this.panel.main.height + 7*MARGIN;
    this.addChild(this.text);
                
    this.startX = this.panel.x - 200;
    this.startY = cheight - 200;
                
    this.turtle = new Turtle(this.startX, this.startY);
    this.addChild(this.turtle);
             
    this.clear = function(){
        this.turtle.clear();
    }
             
                
    this.fun = function(index,commands, helpCommands){
        if(index >= commands.length){
            return;
        }
                    
        var command = commands[index].command;
        var value = commands[index].value;
        switch(command){
            case Forward:
                this.turtle.fd(value);
                this.fun(index + 1,commands,helpCommands);
                break;   
            case Right:
                this.turtle.rt(value);
                this.fun(index + 1,commands,helpCommands);
                break;
            case Left:
                this.turtle.lt(value);
                this.fun(index + 1,commands,helpCommands);
                break;
            case Fx:
                if(helpCommands != null){
                    this.fun(0,helpCommands,null);
                }
                this.fun(index + 1,commands,helpCommands);
                break;   
            case Repeat:
                if(value > 20){
                    break;
                }
                for(var i = 0;i < value;i++){
                    this.fun(index + 1,commands,helpCommands);
                }
                break;
            default:
                console.debug("wrong command");
        }
    }
                
                
    this.generatePicture = function(){
        var main = this.panel.getMainCommands();
        var helpCommands = this.panel.getFunCommands();
        this.fun(0,main,helpCommands);
                    
    }
    
    // compare solutions
    function compare(cmds, sol){
        if(cmds.length != sol.length){
            return false;
        }
        for(var i = 0;i < cmds.length;i++){
            var cmd = cmds[i].command;
            var val = cmds[i].value;
            if(cmd == Fx){
                if(sol[i][0] != Fx){
                    return false;
                }
            }else{
                if(cmd != sol[i][0] || val != sol[i][1]){
                    return false;
                }
            }
        }
        return true;
    }
    
    this.isSolved = function(){
        var result = false;
        var main = this.panel.getMainCommands();
        var funct = this.panel.getFunCommands();
        result |= compare(main,solutionMain1);
        result |= compare(main,solutionMain2);
        result &= compare(funct,solutionFun);
        return result;
    }
                
    this.drawClick = function(e){
        var toto = e.target.parent;
        toto.clear();
        toto.turtle.angle = 0;
        toto.turtle.points = [];
        toto.turtle.setXY(toto.startX, toto.startY);
        toto.generatePicture();  
        toto.turtle.draw();
        if(toto.isSolved()){
           alert('gratulujem'); 
        }
    }
    this.drawButton.addEventListener(MouseEvent.CLICK,this.drawClick);
                
    // Draw start            
    
    this.graphics.beginFill(red);
    this.graphics.drawCircle(this.startX, this.startY,4);
    this.graphics.endFill();
    
    this.startText = new TextField();
    this.startText.setTextFormat(new TextFormat(font, commandSize+5, red));
    this.startText.text = "START"; 
    this.startText.width = this.startText.textWidth + 10; 
    this.startText.height = this.startText.textHeight;
    this.startText.x = this.startX + 2;
    this.startText.y = this.startY + 2;
    this.addChild(this.startText);
                
}
            
TurtleLevel.prototype = new Sprite();>>>>>>> .r36
